package 左旋转字符串;

/**
 * @author zhengTao
 * @version 1.0
 * @description: 剑指 Offer 58 - II. 左旋转字符串
 * @date 2022/10/22 10:56
 */
public class ToOffer58 {
    public static void main(String[] args) {
        String s="abcdefg";
        String s1 = reverseLeftWords(s, 2);
        System.out.println(s1);
    }
    public static String reverseLeftWords(String s, int n) {
        //翻转整个字符串

        String reverse1 = reverse(s, 0, n-1);
        String reverse2 = reverse(reverse1, n , s.length() - 1);
       return reverse(reverse2, 0, s.length() - 1);

    }
    //翻转字符串
    private static String reverse(String newString1, int i, int length) {
        char[] chars = newString1.toCharArray();
        while (i<length){
            char temp=chars[i];
            chars[i]=chars[length];
            chars[length]=temp;
            i++;
            length--;
        }
        return  new String(chars);
    }
}
